home *** CD-ROM | disk | FTP | other *** search
/ Emulator Universe CD / emulatoruniversecd1998.iso / CPC / Utils / CpcFile System / MAKEDOC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-16  |  1.5 KB  |  79 lines

  1. /*                <<<<Last Modified: Tue Jan 16 11:15:24 1996>>>>
  2. */
  3.  
  4.  
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10.  
  11. #define LINELEN 256
  12.  
  13. int main () {
  14.  
  15. const char    help_name[] = "cpcfs.hlp";
  16. const char    template_name[] = "template.doc";
  17. const char    doc_name[] = "doc";
  18.  
  19. char        line[LINELEN];
  20. char        topic[20];
  21. FILE    *help, *template, *doc;
  22. int    found;    /* as bool */
  23.  
  24.     help = fopen(help_name,"r");
  25.     if (help==NULL) {
  26.         fprintf(stderr,"I cannot open \"%s\"",help_name);
  27.         exit(1);
  28.     }
  29.  
  30.     template = fopen(template_name,"r");
  31.     if (template==NULL) {
  32.         fprintf(stderr,"I cannot open \"%s\"",template_name);
  33.         exit(1);
  34.     }
  35.  
  36.     doc = fopen(doc_name,"w");
  37.     if (doc==NULL) {
  38.         fprintf(stderr,"I cannot open \"%s\"",doc_name);
  39.         exit(1);
  40.     }
  41.  
  42.  
  43.     while (fgets(line,LINELEN,template) != NULL) {
  44.         if (line[0]=='~') {
  45.             strncpy(topic,line,20);
  46.             if (topic[strlen(topic)-1]=='\n') {
  47.                 topic[strlen(topic)-1] = 0;
  48.             }
  49.             fseek(help,0L,SEEK_SET);
  50.             found = 0;
  51.             while (fgets(line,LINELEN,help) != NULL) {
  52.                 if (found && line[0]!='~')
  53.                     fputs(line,doc);
  54.                 if (found && line[0]=='~') {
  55.                     found=0;
  56.                     continue;
  57.                 }
  58.                 if (!found&& line[0]!='~')
  59.                     continue;
  60.                 if (!found&& line[0]=='~')
  61.                     found = (strstr(line,topic)!=NULL);
  62.             }
  63.         } else {
  64.             fputs(line,doc);
  65.         }
  66.     }
  67.  
  68.     fclose(doc);
  69.     fclose(template);
  70.     fclose(help);
  71.  
  72.     printf("Merged \"%s\" and \"%s\" to \"%s\"\n",
  73.         template_name, help_name, doc_name);
  74.     printf("You can now copy \"%s\" to \"cpcfs.doc\"\n",
  75.         doc_name);
  76.  
  77.     return 0;    
  78. }
  79.